#include "stdafx.h"
#include "Fakes/FakeD3D11Device.h"
#include "Fakes/FakeD3D11Buffer.h"

DESCRIPTION_11_TEST_SUITE_CTOR(BufferDescription, (2, D3D11_BIND_INDEX_BUFFER))

BOOST_FIXTURE_TEST_CASE(Default, TestBufferDescription)
{
	BOOST_REQUIRE_EQUAL(2, m_desc.ByteWidth);
	BOOST_REQUIRE_EQUAL(D3D11_BIND_INDEX_BUFFER, m_desc.BindFlags);
	BOOST_REQUIRE_EQUAL(D3D11_USAGE_DEFAULT, m_desc.Usage);
	BOOST_REQUIRE_EQUAL(0, m_desc.CPUAccessFlags);
	BOOST_REQUIRE_EQUAL(0, m_desc.MiscFlags);
	BOOST_REQUIRE_EQUAL(0, m_desc.StructureByteStride);
}

#define BUFFER_DESCRIPTION_TEST_CASE(type_, name_, value_) \
	DESCRIPTION_11_SETTER_TEST_CASE(type_, name_, value_, BufferDescription)

BUFFER_DESCRIPTION_TEST_CASE(D3D11_USAGE, Usage, D3D11_USAGE_DYNAMIC)
BUFFER_DESCRIPTION_TEST_CASE(UINT, CPUAccessFlags, D3D11_CPU_ACCESS_READ)
BUFFER_DESCRIPTION_TEST_CASE(UINT, MiscFlags, D3D11_RESOURCE_MISC_SHARED)
BUFFER_DESCRIPTION_TEST_CASE(UINT, StructureByteStride, 32)

BOOST_FIXTURE_TEST_CASE(CreateNoData, TestBufferDescription)
{
	FakeD3D11Device device;
	FakeD3D11Buffer buffer;
	device.CreateBufferFakeResult = &buffer;
	device.CreateBufferFakeHResult = S_OK;
	ID3D11Buffer *result = m_desc.Create(&device);
	BOOST_REQUIRE(device.CreateBufferCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateBufferLastDesc);
	BOOST_REQUIRE_EQUAL(static_cast<D3D11_SUBRESOURCE_DATA const *>(0), device.CreateBufferLastData);
	BOOST_REQUIRE_EQUAL(&buffer, result);
}

BOOST_FIXTURE_TEST_CASE(Create, TestBufferDescription)
{
	FakeD3D11Device device;
	FakeD3D11Buffer buffer;
	device.CreateBufferFakeResult = &buffer;
	device.CreateBufferFakeHResult = S_OK;
	int stuff = 0;
	rt::D3D11::SubResourceData data(&stuff);
	ID3D11Buffer *result = m_desc.Create(&device, &data);
	BOOST_REQUIRE(device.CreateBufferCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateBufferLastDesc);
	BOOST_REQUIRE_EQUAL(&data, device.CreateBufferLastData);
	BOOST_REQUIRE_EQUAL(&buffer, result);
}

BOOST_AUTO_TEST_SUITE_END()
